package threading;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-07-04
 * Time: 15:26
 */
public class ThreadDemo19 {
    public static void main(String[] args) throws InterruptedException {
        BlockingDeque<String> queue = new LinkedBlockingDeque<>();//阻塞队列
        //阻塞队列核心方法
        //1. put 入队列
        queue.put("hello");
        queue.put("hello");
        queue.put("hello");
        queue.put("hello");
        queue.put("hello");
        //2. take 出队列
        String result = queue.take();
        String result1 = queue.take();
        String result2 = queue.take();
        String result3 = queue.take();
        String result4 = queue.take();
        String result5 = queue.take();//由于只有5个元素，所以第六个一直阻塞等待
    }
}
